package com.donn.securitycontrolplatform.dangerousgood.controller;


import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.donn.securitycontrolplatform.common.Result;
import com.donn.securitycontrolplatform.dangerousgood.entity.TStorage;
import com.donn.securitycontrolplatform.dangerousgood.service.ITStorageService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 火工品库存前端控制器
 * </p>
 *
 * @author zhenglx
 * @since 2022-06-19
 */
@RestController
@RequestMapping("/scp/api/storage")
@Tag(name = "storage-controller", description = "库存controller")
public class TStorageController {

    @Autowired
    ITStorageService service;

    @ApiOperation(value = "入库、出库新增")
    @PostMapping("/add")
    @ResponseBody
    public Result add(@ApiParam @RequestBody TStorage storage) {
        return service.insertStorage(storage);
    }

    @ApiOperation(value = "修改库存信息")
    @PutMapping("/update")
    @ResponseBody
    public Result update(@RequestBody TStorage storage) {
        return service.updateStorage(storage);
    }

    @ApiOperation(value = "删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId", value = "角色id")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public Result delete(@RequestParam String storageId) {
        return service.deleteStorage(storageId);
    }


    @ApiOperation(value = "入库详情")
    @GetMapping("/get")
    @ResponseBody
    public Result get(@RequestParam String storageId) {
        return service.getStorageById(storageId);
    }

    @ApiOperation(value = "查询火工品列表")
    @GetMapping("/explosive/list")
    @ResponseBody
    public Result explosiveList(String name, LocalDateTime startTime, LocalDateTime endTime, Page page) {
        page.addOrder(OrderItem.desc("id"));
        return service.selectExplosiveList(name, startTime, endTime, page);
    }



    @ApiOperation(value = "火工品一周出入库情况")
    @GetMapping("/explosive/storageinfo/lastweek/get")
    @ResponseBody
    public Result getLastweekExplosiveStorageInfo() {
        return service.getLastWeekStorageInfo();
    }


    @ApiOperation(value = "火工品本月出入库情况")
    @GetMapping("/explosive/storageinfo/currentMonth/get")
    @ResponseBody
    public Result getCurrentMonthExplosiveStorageInfo() {
        return service.getCurrentMonthExplosiveStorageInfo();
    }

}
